package cn.sinata.wanglin.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.JsonObject;
import com.xilada.xldutils.adapter.HFRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;

import java.util.List;

import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.mine.activity.BlacklistActivity;
import cn.sinata.wanglin.mine.activity.ShieldpersonActivity;
import cn.sinata.wanglin.model.Shieldperson;
import cn.sinata.wanglin.net.HttpManager;
import cn.sinata.wanglin.net.model.util.ResultDataSubscriber;
import cn.sinata.wanglin.utils.ImageUtil;

/**
 * description：
 * Created by kaihongwu on 2016/12/06 下午 9:44
 */
public class ShieldpersonAdapter extends HFRecyclerAdapter<Shieldperson> {
   private Context context;
    private int type;
    public ShieldpersonAdapter(List<Shieldperson> mData, Context context, int type) {
        super(mData, R.layout.item_shieldperson);
        this.context=context;
        this.type=type;
    }

    @Override
    public void onBind(int position, final Shieldperson shieldperson, ViewHolder holder) {
        ((SimpleDraweeView) holder.bind(R.id.headview_mine)).setImageURI(ImageUtil.parseImageUri(shieldperson.getHead_url()));
        if(!TextUtils.isEmpty(shieldperson.getNickName())){
            holder.setText(R.id.tv_name,shieldperson.getNickName());
        }else{
            holder.setText(R.id.tv_name, Constant.DEFULT_NICKNAME);
        }
        if(!TextUtils.isEmpty(shieldperson.getFrom())){
            holder.setText(R.id.tv_from,"来自:"+shieldperson.getFrom());
        }else{
            holder.setText(R.id.tv_from,"暂无认证小区");
        }
        holder.bind(R.id.tv_remove).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (type) {
                    case 0:
                        HttpManager.removeBlacklist(shieldperson.getId()).subscribe(new ResultDataSubscriber<JsonObject>((ShieldpersonActivity) context) {
                            @Override
                            public void onSuccess(String msg, JsonObject jsonObject) {
                                 showToast(msg);
                                showDialog();
                                ((ShieldpersonActivity) context).pullDownRefresh();
                            }
                        });
                        break;
                    case 1:
                        HttpManager.removeBlacklist(shieldperson.getId()).subscribe(new ResultDataSubscriber<JsonObject>((BlacklistActivity) context) {
                            @Override
                            public void onSuccess(String msg, JsonObject jsonObject) {
                                showToast(msg);
                                showDialog();
                                ((BlacklistActivity) context).pullDownRefresh();
                            }
                        });
                        break;
                }
            }


        });
    }
}
